package com.zygh.policeasset.controller;

import cn.hutool.core.util.StrUtil;
import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.Completed;
import com.zygh.policeasset.pojo.Contract;
import com.zygh.policeasset.pojo.FinalStatement;
import com.zygh.policeasset.pojo.Project;
import com.zygh.policeasset.pojo.Settlement;
import com.zygh.policeasset.pojo.Tender;
import com.zygh.policeasset.service.CompletedSerivce;
import com.zygh.policeasset.service.ContractService;
import com.zygh.policeasset.service.ExcelService;
import com.zygh.policeasset.service.FinalStatementService;
import com.zygh.policeasset.service.ProjectService;
import com.zygh.policeasset.service.SettlementService;
import com.zygh.policeasset.service.TenderService;
import com.zygh.policeasset.utils.EasyExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/excel"})
@Api(tags = {"表格"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/ExcelController.class */
public class ExcelController {
    @Autowired
    private ExcelService excelService;
    @Autowired
    ProjectService projectService;
    @Autowired
    TenderService tenderService;
    @Autowired
    ContractService contractService;
    @Autowired
    CompletedSerivce completedSerivce;
    @Autowired
    SettlementService settlementService;
    @Autowired
    FinalStatementService finalStatementService;

    @RequestMapping(value = {"/getassets"}, produces = {"application/json;charset=UTF-8"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "sectionId", value = "资产标段，type为zd和da可不传", required = true, paramType = "query"), @ApiImplicitParam(name = "buildNum", value = "项目编号", required = true, paramType = "query"), @ApiImplicitParam(name = "type", value = "资产类型,zn：智能硬件+软件, jc：基础,cg：采购,da：日常资产", required = true, paramType = "query")})
    @ApiOperation("导出采购资产表格")
    public Object getExcel(HttpServletResponse response, @RequestParam(value = "sectionId", required = false) Integer sectionId, @RequestParam(value = "buildNum", required = false) String buildNum, @RequestParam(value = "type", required = false) String type) {
        if (StrUtil.isEmpty(buildNum)) {
            return new CommonResult().validateFailed("项目编号不能为空");
        }
        if (StrUtil.isEmpty(type)) {
            return new CommonResult().validateFailed("类型不能为空");
        }
        String path = this.excelService.getExcel(response, sectionId, buildNum, type);
        if ("导出失败！".equals(path) || "无资产数据！".equals(path)) {
            return new CommonResult().validateFailed(path);
        }
        return new CommonResult().success(path);
    }

    @RequestMapping(value = {"/getAssetCard"}, produces = {"application/json;charset=UTF-8"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "sectionId", value = "资产标段，type为采购和日常可不传", required = true, paramType = "query"), @ApiImplicitParam(name = "buildNum", value = "项目编号", required = true, paramType = "query"), @ApiImplicitParam(name = "type", value = "资产类型,zn：智能硬件+软件, jc：基础,cg：采购,da：日常资产", required = true, paramType = "query")})
    @ApiOperation("导出资产卡片")
    public Object getAssetCard(@RequestParam(value = "sectionId", required = false) Integer sectionId, @RequestParam(value = "buildNum", required = false) String buildNum, @RequestParam(value = "type", required = false) String type) throws IOException {
        return this.excelService.getAssetCard(sectionId, buildNum, type);
    }

    @RequestMapping(value = {"/report"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "资产类型 '':全部类型 zn：智能硬件+软件 jc：基础 zd：采购", required = true, paramType = "query"), @ApiImplicitParam(name = "startTime", value = "起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "endTime", value = "结束日期", required = true, paramType = "query"), @ApiImplicitParam(name = "pageNum", value = "页码", required = true, paramType = "query"), @ApiImplicitParam(name = "pageSize", value = "页数", required = true, paramType = "query")})
    @ApiOperation("查询报表")
    public Object report(String type, String startTime, String endTime) throws Exception {
        return this.excelService.report(type, startTime, endTime);
    }

    @RequestMapping(value = {"/getreport"}, produces = {"application/json;charset=UTF-8"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "type", value = "资产类型 '':全部类型 zn：智能硬件+软件 jc：基础 zd：采购", required = true, paramType = "query"), @ApiImplicitParam(name = "startTime", value = "起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "endTime", value = "结束日期", required = true, paramType = "query")})
    @ApiOperation("导出资产压缩包")
    public Object getReport(String type, String startTime, String endTime) throws Exception {
        String path = this.excelService.getReport(type, startTime, endTime);
        if ("导出失败！".equals(path) || "无资产数据！".equals(path)) {
            return new CommonResult().validateFailed(path);
        }
        System.out.println(path);
        return new CommonResult().success(path.substring(path.indexOf(":") + 1));
    }

    @RequestMapping(value = {"/assetscount"}, method = {RequestMethod.GET})
    public Object assetsCountNew(@RequestParam(defaultValue = "1", value = "pageNum") int pageNum, @RequestParam(defaultValue = "10", value = "pageSize") int pageSize, @RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("type") String type) {
        if (StrUtil.isEmpty(startTime)) {
            return new CommonResult().validateFailed("开始日期不能为空");
        }
        if (StrUtil.isEmpty(endTime)) {
            return new CommonResult().validateFailed("结束日期不能为空");
        }
        if (StrUtil.isEmpty(type)) {
            return new CommonResult().validateFailed("类型不能为空");
        }
        return this.excelService.reportCount(pageNum, pageSize, startTime, endTime, type);
    }

    @RequestMapping(value = {"/projectexcle"}, method = {RequestMethod.GET}, produces = {"application/json;charset=UTF-8"})
    @ApiOperation("项目导出")
    public Object projectexcle(HttpServletResponse response, @RequestParam(value = "type", required = false) String type, @RequestParam(value = "name", required = false) String name, @RequestParam(value = "companyId", required = false) String companyId, @RequestParam(value = "time1", required = false) String time1, @RequestParam(value = "time2", required = false) String time2) throws IOException {
        if (StrUtil.isEmpty(type)) {
            return new CommonResult().validateFailed("项目类型不能为空");
        }
        EasyExcelUtil easyExcelUtil = new EasyExcelUtil();
        if (type.equals("project")) {
            List<Project> projectListjc = this.projectService.toExcel(2);
            List<Project> projectListzn = this.projectService.toExcel(1);
            List<Project> projectListcg = this.projectService.toExcel(4);
            if (((projectListjc.size() == 0) & (projectListzn.size() == 0)) && (projectListcg.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelProject("立项项目统计", response, projectListjc, projectListzn, projectListcg);
        } else if (type.equals("tender")) {
            List<Tender> tenderListjc = this.tenderService.toExcel(2, name, time1, time2);
            List<Tender> tenderListzn = this.tenderService.toExcel(1, name, time1, time2);
            List<Tender> tenderListcg = this.tenderService.toExcel(4, name, time1, time2);
            if (((tenderListjc.size() == 0) & (tenderListzn.size() == 0)) && (tenderListcg.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelTender("招标项目统计", response, tenderListjc, tenderListzn, tenderListcg);
        } else if (type.equals("contract")) {
            List<Contract> tenderListjc2 = this.contractService.toExcel(2, name, companyId, time1, time2);
            List<Contract> tenderListzn2 = this.contractService.toExcel(1, name, companyId, time1, time2);
            List<Contract> tenderListcg2 = this.contractService.toExcel(4, name, companyId, time1, time2);
            if (((tenderListjc2.size() == 0) & (tenderListzn2.size() == 0)) && (tenderListcg2.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelContract("合同项目统计", response, tenderListjc2, tenderListzn2, tenderListcg2);
        } else if (type.equals("completed")) {
            List<Completed> completedListjc = this.completedSerivce.toExcel(2, name, companyId, time1, time2);
            List<Completed> completedListzn = this.completedSerivce.toExcel(1, name, companyId, time1, time2);
            List<Completed> completedListcg = this.completedSerivce.toExcel(4, name, companyId, time1, time2);
            if (((completedListjc.size() == 0) & (completedListzn.size() == 0)) && (completedListcg.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelCompleted("竣工验收项目统计", response, completedListjc, completedListzn, completedListcg);
        } else if (type.equals("settlement")) {
            List<Settlement> settlementListjc = this.settlementService.toExcel(2, name, companyId, time1, time2);
            List<Settlement> settlementListzn = this.settlementService.toExcel(1, name, companyId, time1, time2);
            List<Settlement> settlementListcg = this.settlementService.toExcel(4, name, companyId, time1, time2);
            if (((settlementListjc.size() == 0) & (settlementListzn.size() == 0)) && (settlementListcg.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelSettlement("审计结算项目统计", response, settlementListjc, settlementListzn, settlementListcg);
        } else if (!type.equals("finalStatement")) {
            return "导出失败";
        } else {
            List<FinalStatement> finalStatementListjc = this.finalStatementService.toExcel(2, name, companyId, time1, time2);
            List<FinalStatement> finalStatementListzn = this.finalStatementService.toExcel(1, name, companyId, time1, time2);
            List<FinalStatement> finalStatementListcg = this.finalStatementService.toExcel(4, name, companyId, time1, time2);
            if (((finalStatementListjc.size() == 0) & (finalStatementListzn.size() == 0)) && (finalStatementListcg.size() == 0)) {
                return new CommonResult().validateFailed("查询无数据");
            }
            return easyExcelUtil.easyExcelFinalStatement("审计决算项目统计", response, finalStatementListjc, finalStatementListzn, finalStatementListcg);
        }
    }

    @RequestMapping(value = {"/depratebytimeNew"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "startTime", value = "启用起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "endTime", value = "启用结束日期", required = true, paramType = "query"), @ApiImplicitParam(name = "time1", value = "折旧起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "time2", value = "折旧结束日期", required = true, paramType = "query"), @ApiImplicitParam(name = "condition", value = "是否过滤已折旧完数据(0是移除、1是不移除)", required = true, paramType = "query"), @ApiImplicitParam(name = "dataLabelsId", value = "数据标签", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationId", value = "资产子ID", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationPid", value = "资产父ID", required = true, paramType = "query")})
    @ApiOperation("查询时间段的的资产在时间段内的折旧(新)")
    public Object depratebytimeNew(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String time1, @RequestParam(required = false) String time2, @RequestParam(required = false) Integer condition, @RequestParam(required = false) Integer dataLabelsId, @RequestParam(required = false) Integer assetsClassificationId, @RequestParam(required = false) Integer assetsClassificationPid) throws Exception {
        return this.excelService.depratebytimeNew(startTime, endTime, time1, time2, condition, dataLabelsId, assetsClassificationId, assetsClassificationPid);
    }

    @RequestMapping(value = {"/depratebytimeNewExport"}, method = {RequestMethod.GET})
    @ApiImplicitParams({@ApiImplicitParam(name = "startTime", value = "启用起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "endTime", value = "启用结束日期", required = true, paramType = "query"), @ApiImplicitParam(name = "time1", value = "折旧起始日期", required = true, paramType = "query"), @ApiImplicitParam(name = "time2", value = "折旧结束日期", required = true, paramType = "query"), @ApiImplicitParam(name = "condition", value = "是否过滤已折旧完数据(0是移除、1是不移除)", required = true, paramType = "query"), @ApiImplicitParam(name = "dataLabelsId", value = "数据标签", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationId", value = "资产子ID", required = true, paramType = "query"), @ApiImplicitParam(name = "assetsClassificationPid", value = "资产父ID", required = true, paramType = "query")})
    @ApiOperation("查询时间段的的资产在时间段内的折旧(新)导出")
    public Object depratebytimeNewExport(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime, @RequestParam(required = false) String time1, @RequestParam(required = false) String time2, @RequestParam(required = false) Integer condition, @RequestParam(required = false) Integer dataLabelsId, @RequestParam(required = false) Integer assetsClassificationId, @RequestParam(required = false) Integer assetsClassificationPid, HttpServletResponse response) throws Exception {
        return this.excelService.depratebytimeNewExport(startTime, endTime, time1, time2, condition, dataLabelsId, assetsClassificationId, assetsClassificationPid, response);
    }
}